<template>
    <block v-if="scene == 1154">
    	<pyq-open-chunk></pyq-open-chunk>
    </block>
    <block v-else>
        <view class="adviserPage bg-fff">
            <block v-for="(item,index) in list" :key="index">
                <view class="top-20">
                    <adviser-item :rankIndex="index" :isRank="true" :detail="item"></adviser-item>
                </view>
            </block>
            <view class="empty flex font13 col-grey">暂无更多</view>
        </view>
    </block>
</template>
<script>
    import { mapState, mapActions } from 'pinia';
    import { useIndexStore, useUserInfoStore, useConfigStore } from '@/store/index';
	import { adviserList } from '@/common/api';
    import { isBoolean } from '@/common/common';
    // import { dispatchClient } from '@/common/api-adviser';

	export default {
		data() {
			return {
				list: [],
                productId: '',
                title: '',
                share: false,
                start_time: 0
            }
		},
        computed:{
            ...mapState(useIndexStore, ['nowCityCode']),
            ...mapState(useUserInfoStore, ['userInfo']),
            ...mapState(useConfigStore, ['scene']),
        },
        onShareAppMessage(res) {
            return {
                title: `${this.title}置业顾问，点击查看`,
                path: `/pages/my/adviser/pages?productId=${this.productId}&title=${this.title}&puid=${this.userInfo.id}&share=true&prepage=置业顾问-${this.userInfo.id}-${this.title}`,
            }
        },
        //#ifdef MP-WEIXIN
        onShareTimeline() {
            return {
                title: `${this.title}置业顾问，点击查看`,
                query: `productId=${this.productId}&title=${this.title}&puid=${this.userInfo.id}&share=true&prepage=置业顾问-${this.userInfo.id}-${this.title}`
            }
        },
        //#endif
		onLoad(options){
            const that = this;
			let { id='', productId='', title='', puid='', share=false } = options;
            
            //朋友圈进入小程序快照场景
            if(this.scene == 1154) return;
            
            if(puid&&puid!=='undefined') {
                this.setPuid(puid)
            }
			this.productId = id?id:productId;
			this.title = title&&title!=='undefined'?title:'';
            this.share = isBoolean(share);
            this.start_time = (new Date()).getTime();
           
            uni.$check_and_login(function () {
                //绑定客户
                // dispatchClient({
                //     share: that.share,
                //     puid: puid,
                //     pid: that.productId
                // });
            	that.init();
            })
		},

        methods: {
            ...mapActions(useConfigStore, ['setPuid']),
			init() {
                uni.showLoading({
                	title: '数据加载中',
                	mask: true
                })
                adviserList({
                    id: this.productId,
                    cityCode: this.nowCityCode
                }).then(res => {
                    if(res.status == 0){
                        this.list = res.detail;
                        uni.hideLoading();
                    }else{
                        uni.hideLoading();
                        uni.$u.toast(res.detail)
                    }
                }).catch(err => {
                    uni.hideLoading();
                })
            }
		}
	}
</script>

<style lang="scss" scoped>
	.adviserPage{
        min-height: 100vh;
        padding: 0rpx 28rpx;
        overflow: hidden;
    }
</style>
